package com.huawei.appgallery.wishlist.bean;

import android.text.TextUtils;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import o.dch;
import o.dct;

public class WishInfoListCache extends JsonBean {
    private static final String TAG = "WishInfoListCache";
    private static WishInfoListCache instance;
    private Map<String, WishInfoCache> cacheMap_ = new ConcurrentHashMap();

    public static final class WishInfoCache extends JsonBean {
        private String appName_;
        private int isAutoInstall_;
        private String pkg_;
        private int versionCode_;

        public String ˋ() {
            return this.pkg_;
        }

        public void ˏ(String str) {
            this.pkg_ = str;
        }

        public void ˊ(int i) {
            this.isAutoInstall_ = i;
        }

        public int ॱ() {
            return this.versionCode_;
        }

        public void ˎ(int i) {
            this.versionCode_ = i;
        }

        public void ॱ(String str) {
            this.appName_ = str;
        }
    }

    public static synchronized WishInfoListCache ˊ() {
        WishInfoListCache ˎ;
        synchronized (WishInfoListCache.class) {
            if (instance == null) {
                instance = new WishInfoListCache();
                ˎ = dct.ˏ().ˎ();
                instance.cacheMap_ = ˎ.cacheMap_;
            }
            ˎ = instance;
        }
        return ˎ;
    }

    public int ˎ() {
        int size;
        synchronized (this.cacheMap_) {
            size = this.cacheMap_.size();
        }
        return size;
    }

    public int ˋ() {
        int i = 0;
        synchronized (this.cacheMap_) {
            for (WishInfoCache wishInfoCache : this.cacheMap_.values()) {
                int i2;
                if (wishInfoCache == null || wishInfoCache.isAutoInstall_ != 1) {
                    i2 = i;
                } else {
                    i2 = i + 1;
                }
                i = i2;
            }
        }
        return i;
    }

    public String ˎ(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder();
        synchronized (this.cacheMap_) {
            for (Entry entry : this.cacheMap_.entrySet()) {
                if (str.equals(((WishInfoCache) entry.getValue()).ˋ())) {
                    stringBuilder.append((String) entry.getKey()).append(",");
                }
            }
        }
        String stringBuilder2 = stringBuilder.toString();
        if (stringBuilder2.endsWith(",")) {
            return stringBuilder2.substring(0, stringBuilder.length() - ",".length());
        }
        return stringBuilder2;
    }

    public void ˎ(String str, String str2, String str3, int i, int i2, boolean z) {
        if (!TextUtils.isEmpty(str)) {
            WishInfoCache wishInfoCache = new WishInfoCache();
            wishInfoCache.ˏ(str3);
            wishInfoCache.ˎ(i);
            wishInfoCache.ˊ(i2);
            wishInfoCache.ॱ(str2);
            synchronized (this.cacheMap_) {
                this.cacheMap_.put(str, wishInfoCache);
            }
            if (z) {
                dct.ˏ().ˎ(this);
            }
        }
    }

    public void ˎ(boolean z) {
        synchronized (this.cacheMap_) {
            this.cacheMap_.clear();
        }
        if (z) {
            ॱ();
        }
    }

    public void ˊ(String str, boolean z) {
        if (TextUtils.isEmpty(str)) {
            dch.ˎ.ˊ(TAG, "empty wishId.");
            return;
        }
        synchronized (this.cacheMap_) {
            this.cacheMap_.remove(str);
        }
        if (z) {
            ॱ();
        }
    }

    public void ˎ(String str, boolean z) {
        if (TextUtils.isEmpty(str)) {
            dch.ˎ.ˊ(TAG, "empty pkg.");
            return;
        }
        synchronized (this.cacheMap_) {
            Set<Entry> entrySet = this.cacheMap_.entrySet();
            List<String> arrayList = new ArrayList();
            for (Entry entry : entrySet) {
                WishInfoCache wishInfoCache = (WishInfoCache) entry.getValue();
                if (wishInfoCache != null && str.equals(wishInfoCache.ˋ())) {
                    arrayList.add(entry.getKey());
                }
            }
            for (String remove : arrayList) {
                this.cacheMap_.remove(remove);
            }
        }
        if (z) {
            ॱ();
        }
    }

    public void ॱ() {
        synchronized (this.cacheMap_) {
            dct.ˏ().ˎ(this);
        }
    }

    public Map<String, WishInfoCache> ˏ() {
        Map concurrentHashMap;
        synchronized (this.cacheMap_) {
            concurrentHashMap = new ConcurrentHashMap(this.cacheMap_);
        }
        return concurrentHashMap;
    }
}
